//
//  ViewController.m
//  03-UIPesponder
//
//  Created by 李昊林 on 16/7/18.
//  Copyright © 2016年 李昊林. All rights reserved.
//

#import "ViewController.h"
#import "TouchView.h"
#import "AppDelegate.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    TouchView *touchView = [[TouchView alloc] initWithFrame:CGRectMake(10, 10, 355, 200)];
    touchView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:touchView];
    //练习1：
    //1.响应者链
    //触摸TouchView时
    //检测顺序：硬件->Appdelegate->UIApplicatiom->UIWindow->UIViewController->self.view->TouchView
    //响应顺序：TouchView->self.View->UIViewController->UIWindow->UIApplication->Appdelegate->null
    //如果所有的响应者都无法响应，则这个事件就会被舍弃（放弃）
    //两种检测响应者方法
    //1.Category 实现TouchBegin的方法
    //2.nextResponder
    
    //例：
    //响应者不要出边界，出边界的响应者无法响应
    //判断当前点在谁的范围内
    bool isInside = [touchView pointInside:CGPointMake(10, 10) withEvent:nil];
    NSLog(@"%@", isInside ? @"YES":@"NO");
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(10, 10, 200, 50);
    button.backgroundColor = [UIColor greenColor];
    [touchView addSubview:button];
    [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    //Button的点击方法如何让实现
    //button点击效果，通过UIResponder对应的方法实现
    //3.pointINside重写，实现失去能力（return NO）
}

- (void)buttonClick:(UIButton *)button {
    NSLog(@"%@",button);
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    NSLog(@"%@ %s", [self class] ,__FUNCTION__);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
